package com.uy.cuantoconocesdeuruguay.utiles;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class ListUtils {
	public static void shuffleList(List<Integer> list) {
		int n = list.size();
		Random random = new Random();
		random.nextInt();
		for (int i = 0; i < n; ++i) {
			int change = i + random.nextInt(n - i);
			swap(list, i, change);
		}
	}
	
	
	public static int[] shuffleArray(int[] array){
		List<Integer> list = new LinkedList<Integer>();
		for (int i : array){
			list.add(i);
		}
		shuffleList(list);
		int[] shuffled = new int[list.size()];
		int j = 0;
		for (int i : list){
			shuffled[j] = i;
			++j;
		}
		return shuffled;
	}

	private static void swap(List<Integer> list, int index, int change) {
		int pivot = list.get(index);
		list.set(index, list.get(change));
		list.set(change, pivot);
	}
}
